package org.afun.oldhand.order.adapter;

import android.content.Context;
import android.media.Image;
import android.telephony.ims.RcsUceAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.afun.oldhand.R;
import org.afun.oldhand.order.javaBean.Item1Bean;
import org.w3c.dom.Text;

import java.util.List;

public class OrderItem1Adater extends RecyclerView.Adapter<OrderItem1Adater.OrderView1Holder> {
    private List<Item1Bean> data;
    private Context context;
    private OnOrderRecyclerItem1ClickListener onOrderRecyclerItem1ClickListener;

    public OrderItem1Adater(List<Item1Bean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @NonNull
    @Override
    public OrderItem1Adater.OrderView1Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.order1_listitem,parent,false);
        return  new OrderView1Holder(view);
    }


    @Override
    public void onBindViewHolder(@NonNull OrderView1Holder holder, int position) {
        holder.coachImage.setImageResource(data.get(position).getCoachImage());
        holder.coachName.setText(data.get(position).getCoachName());
        holder.spendTime.setText(data.get(position).getSpendTime());
        holder.spendFee.setText(data.get(position).getSpendFee());
        holder.predicttime.setText(data.get(position).getPredicttime());
        holder.coachmap.setImageResource(data.get(position).getCoachmap());

    }



    @Override
    public int getItemCount() {
        return data == null ? 0: data.size();
    }

    public class OrderView1Holder extends RecyclerView.ViewHolder{
        ImageView coachImage;
        TextView coachName;
        TextView spendTime;
        TextView spendFee;
        TextView predicttime;
        ImageView coachmap;
        Button phone;


        public OrderView1Holder(@NonNull View itemView) {
            super(itemView);
            coachImage = itemView.findViewById(R.id.order1_img);
            coachName = itemView.findViewById(R.id.order1_coachname);
            spendTime = itemView.findViewById(R.id.order1_spendtime);
            spendFee = itemView.findViewById(R.id.order1_spendfee);
            predicttime = itemView.findViewById(R.id.order1_predicttime);
            coachmap = itemView.findViewById(R.id.order1_coachmap);
            phone = itemView.findViewById(R.id.order1_phone);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onOrderRecyclerItem1ClickListener != null){
                        onOrderRecyclerItem1ClickListener.onItem1RecyclerItemClick(getAdapterPosition());
                    }
                }

            });
        }
    }

    public void setOrderItem1ClickListener(OnOrderRecyclerItem1ClickListener listener){
        onOrderRecyclerItem1ClickListener = listener;
    }


    public interface OnOrderRecyclerItem1ClickListener{
        void onItem1RecyclerItemClick(int position);
    }
}
